package com.guang.file;

import java.io.File;
import java.io.FileFilter;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Objects;

/**
 * @author lg
 * @Description
 * @date 2022/10/17 9:32
 */
public class FileTestOne {
    public static void main(String[] args) {

        File file = new File("D:\\总结资料");
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        File[] files = file.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                long l = pathname.lastModified();
                Date fileDate = new Date(l);
                Date date = new Date();
                String fileDateString = fmt.format(fileDate);
                String nowDate = fmt.format(date);
                boolean flag = Objects.equals(fileDateString, nowDate);
                if (flag) {
                    System.out.println(String.format("当前的文件路径是：%s，当前的文件名称是：%s", pathname.getAbsolutePath(), pathname.getName()));
                }
                return flag;
            }
        });
        System.out.println("当前的文件集合中的数据是："+ Arrays.toString(files));

    }
}
